/*
 * Created by Jaren at 2021/12/20 10:19
 */
import 'dart:typed_data';

import 'package:inmotion_protocol/common/product_version.dart';
import 'package:inmotion_protocol/common/vehicle_info.dart';
import 'package:inmotion_protocol/lorin/factory/special/scooter/scooter_message_factory.dart';
import 'package:inmotion_protocol/lorin/lorin_message.dart';

class S1MessageFactory extends ScooterLorinSpecialMessageFactory<_S1Cmd> {
  S1MessageFactory(ProductProperty productProperty) : super(productProperty);

  @override
  void initCompact(int apiVersion, VersionWrapper version) {
    compact = S1CmdDefault();
  }

  LorinMessage genCalibrateIMUMsg() {
    /// S1中，校准IMU和校准把手指令相同，校准类型参数为2
    return genCalibrateHandleMsg(2);
  }

  LorinMessage genQueryIMUCalibrationMsg() {
    /// S1中，查询IMU校准结果和查询把手校准结果指令相同，校准类型参数为2
    return genQueryHandleCalibrationResultMsg(2);
  }

  LorinMessage genHacOnOffMsg(bool on) {
    return genSpecialOne2OneWriteMsg(compact!.hacCmd(), Uint8ClampedList.fromList([on ? 1 : 0]));
  }

  LorinMessage genHdcOnOffMsg(bool on) {
    return genSpecialOne2OneWriteMsg(compact!.hdcCmd(), Uint8ClampedList.fromList([on ? 1 : 0]));
  }

  @override
  LorinMessage genSetLightEffectModeMsg(int mode, [Uint8ClampedList? param, int? source, int? target]) {
    return genSpecialOne2OneWriteMsg(compact!.lightEffectModeCmd(), Uint8ClampedList.fromList([mode]));
  }
}

abstract class _S1Cmd extends ScooterCmdCompact {
  int hacCmd();

  int hdcCmd();

  int lightEffectModeCmd();
}

class S1CmdDefault extends _S1Cmd {
  @override
  int lightEffectModeCmd() {
    return 20;
  }

  @override
  int hdcCmd() {
    return 30;
  }

  @override
  int hacCmd() {
    return 31;
  }
}
